#ifndef __MVP_COMM_H__
#define __MVP_COMM_H__

#include "mvvcd.h"
#include "mvt_utilities/mvt_log.h"
#if __cplusplus
extern "C" {
#endif

typedef enum _firmware_type
{
/************安凯ev330 linux方案固件类型区域100-199*************/
    FIRMWARE_TYPE_AKEV330                           = 100,
    FIRMWARE_TYPE_AK_PTZ_Q8_V5_0                    = 100,
    FIRMWARE_TYPE_AK_PTZ_ETH_V6_0                   = 101,
    FIRMWARE_TYPE_AKEV330_MAX                       = 199,

/************安凯ev330 alios方案固件类型区域200-299*************/
    FIRMWARE_TYPE_ALIEV330                          = 200,
    FIRMWARE_TYPE_AK_ALIEV330_PTZ_Q8_ETH_WF_V6_0    = 200,
    FIRMWARE_TYPE_AK_ALIEV330_YW_Q18H_V2_0          = 201,
    FIRMWARE_TYPE_AK_ALIEV330_YW_AK008_V2_0         = 202,
    FIRMWARE_TYPE_AK_ALIEV330_PTZ_Q8_ETH_4G_V10     = 203,
    FIRMWARE_TYPE_AK_ALIEV330_Q12_CAT_V6_0          = 204,
    FIRMWARE_TYPE_ALIEV330_MAX                      = 299,

/************富瀚8626v100 linux方案固件类型区域300-399*************/
    FIRMWARE_TYPE_FH8626V100                        = 300,
    FIRMWARE_TYPE_FH8626V100_PTZ_XHR_V3_0           = 300,
    FIRMWARE_TYPE_FH8626V100_D5                     = 301,
    FIRMWARE_TYPE_FH8626V100_MAX                    = 399,
///< AK alios-av100 400-500
#define FIRMWARE_TYPE_AK_ALIEAV100_PTZ_P12_ETH_WF_V1_1     400

#define FIRMWARE_PC_4G   1000
#define FIRMWARE_PC_WIFI 1001

/************安凯av100 linux方案固件类型区域400-499*************/
    FIRMWARE_TYPE_AKAV100                           = 400,

/************安凯av100 alios方案固件类型区域500-599*************/
    FIRMWARE_TYPE_AK_ALIAV100_P_P12_WF              = 500,
    FIRMWARE_TYPE_AK_ALIAV100_N_P12_WF              = 501,
    FIRMWARE_TYPE_AK_ALIAV100_N_P12_4G              = 502,
    FIRMWARE_TYPE_AK_ALIAV100_N_Q2_WF               = 503,
    FIRMWARE_TYPE_AK_ALIAV100_N_Q2_4G               = 504,

/* 鹰炜方案暂时从530开始**/
    FIRMWARE_TYPE_ALIAV100N_YW_WF                   = 530,
/* 低功耗方案暂时从550开始**/
    FIRMWARE_TYPE_ALIAV100_LP_EC800GCN_P5           = 550,
    FIRMWARE_TYPE_ALIAV100_LP_Air780E_P5            = 551,
    FIRMWARE_TYPE_ALIAV100_LP_HI3861L               = 552,
    FIRMWARE_TYPE_ALIAV100_MAX                      = 599,

/************安凯ev200/201 alios方案固件类型区域600-699*************/
    FIRMWARE_TYPE_ALIEV200                          = 600,
    FIRMWARE_TYPE_AK_ALIEV200_201_Q6S_WF		    = 600,
    FIRMWARE_TYPE_AK_ALIEV200_201_Q6PRO_WF		    = 601,
    FIRMWARE_TYPE_AK_ALIEV200_50CARD_WF 		    = 602,
    FIRMWARE_TYPE_AK_ALIEV200_Q8_EXTERN_IO_WF      	= 603,
    FIRMWARE_TYPE_AK_ALIEV200_38_WF      		    = 604,
    FIRMWARE_TYPE_AK_ALIEV200_60PANORAMIC_WF      	= 605,
    FIRMWARE_TYPE_AK_ALIEV201_YWQ16A_WF		        = 606,
    FIRMWARE_TYPE_AK_ALIEV201_XHR_WF		        = 607,
    FIRMWARE_TYPE_AK_ALIEV200_201_Q6S_SMOKE_WF	    = 608, ///< Q6S变种,ADC外接烟感特殊设备
    FIRMWARE_TYPE_ALIEV200_MAX                      = 699,

/************君正T31ZL_LP方案固件类型区域700-799*************/
    FIRMWARE_TYPE_JZT31ZL_LP                        = 700,
    FIRMWARE_TYPE_JZT31ZL_LP_PTZ_ATBM6441           = 701,
    FIRMWARE_TYPE_JZT31ZL_LP_PTZ_AIR724UG           = 702,
    FIRMWARE_TYPE_JZT31ZL_LP_PTZ_EC800GCN           = 703,
    FIRMWARE_TYPE_JZT31ZL_LP_PTZ_EC600U             = 704,
    FIRMWARE_TYPE_JZT31ZL_LP_PTZ_H3861L             = 705,

    FIRMWARE_TYPE_JZT31ZL_LP_EC800GCN_XVV_P9DL      = 750,
    FIRMWARE_TYPE_JZT31ZL_LP_MAX                    = 799,

/************君正T40方案固件类型区域800-899*************/
    FIRMWARE_TYPE_JZT40                             = 800,
    FIRMWARE_TYPE_JZT40_MAX                         = 899,

/************君正T31ZL_LP方案固件类型区域900-999*************/
    FIRMWARE_TYPE_JZT31ZX_LP                        = 900,
    FIRMWARE_TYPE_JZT31ZX_LP_PTZ_ATBM6441           = 901,
    FIRMWARE_TYPE_JZT31ZX_LP_PTZ_AIR724UG           = 902,
    FIRMWARE_TYPE_JZT31ZX_LP_PTZ_EC800GCN           = 903,
    FIRMWARE_TYPE_JZT31ZX_LP_PTZ_EC600U             = 904,
    FIRMWARE_TYPE_JZT31ZX_LP_MAX                    = 999,

/************安凯EV300L linux 1000-1099 *************/
    FIRMWARE_TYPE_AK_EV300L                         = 1000,
    FIRMWARE_TYPE_AK_EV300L_XVV_Q2_4G               = 1001,
    FIRMWARE_TYPE_AK_EV300L_XVV_Q2_WIFI             = 1002,
    // 1-49 为XVV平台，50-99为 V380平台
    FIRMWARE_TYPE_AK_EV300L_V380_Q2_4G              = 1050,
    FIRMWARE_TYPE_AK_EV300L_V380_Q2_WIFI            = 1051,
    FIRMWARE_TYPE_AK_EV300L_V380_XHR_4G             = 1052,
    FIRMWARE_TYPE_AK_EV300L_V380_XHR_WIFI           = 1053,

/************安凯 KM01D LINUX 枪球方案固件类型区域2000-2099*************/
    FIRMWARE_TYPE_AKKM01D_V380_QQ_PTZ_EXTERN_IO_4G  = 2000,
    FIRMWARE_TYPE_AKKM01D_V380_QQ_PTZ_EXTERN_IO_WF  = 2001,

    FIRMWARE_TYPE_AKKM01D_XVV_QQ_PTZ_EXTERN_IO_4G   = 2050,
    FIRMWARE_TYPE_AKKM01D_XVV_QQ_PTZ_EXTERN_IO_WF   = 2051,
/************安凯 KM01D ALIOS 枪球方案固件类型区域2100-2199*************/
    FIRMWARE_TYPE_ALIKM01D_QQ_PTZ_EXTERN_IO_4G      = 2100,
    FIRMWARE_TYPE_ALIKM01D_QQ_PTZ_EXTERN_IO_WF      = 2101,

/************安凯 KM01D ALIOS 枪球低功耗方案固件类型区域2200-2299 *************/
    FIRMWARE_TYPE_ALIKM01D_QQ_LP_PTZ_4G             = 2200,
    FIRMWARE_TYPE_ALIKM01D_QQ_LP_TYPE_MAX           = 2299,

/************调试方案固件类型区域9000-9099*************/
    FIRMWARE_TYPE_PC_4G                             = 9000,
    FIRMWARE_TYPE_PC_WIFI                           = 9001,
/************ 新平台  >10000 *************/
/************安凯ev200/201 alios 新平台方案固件类型区域10000-10099*************/
    FIRMWARE_TYPE_ALIEV200_NP                       = 10000,
    FIRMWARE_TYPE_AK_ALIEV200L_MVT3610S2_D_V10      = 10001,
    FIRMWARE_TYPE_AK_ALIEV200W_MVT3610S_W_XHR_V1    = 10007,
    FIRMWARE_TYPE_AK_ALIEV200W_LY05S                = 10008,
    FIRMWARE_TYPE_AK_ALIEV200W_K9                   = 10009,
    FIRMWARE_TYPE_AK_ALIEV200W_MVT3610S_W_XHR_E_V1  = 10010,
    FIRMWARE_TYPE_AK_ALIEV200X_MVR3313W_A3_V1       = 10011,
    FIRMWARE_TYPE_ALIEV200_NP_MAX                   = 10099,
    
/**************安凯av100n linux新平台方案固件类型区域10100-10199***************/
    FIRMWARE_TYPE_AKAV100_NP                        = 10100,
/* 鹰炜方案暂时从10130开始**/
    FIRMWARE_TYPE_AKAV100_YWX22_WF                  = 10130,
    FIRMWARE_TYPE_AKAV100_NP_MAX                    = 10199,

/*************雄迈新平台方案固件类型区域11000-11099*****************************/
    FIRMWARE_TYPE_XM530V203_MVS5620S_XHR_WF         = 11001,

}FIRMWARE_TYPE_E;

#pragma region config
enum _gpio_def
{
    GPIO_IRCUT_A1 = 0,
	GPIO_IRCUT_B1,
	GPIO_IRCUT_A2,
	GPIO_IRCUT_B2,
	GPIO_IR_LED1,
	GPIO_IR_LED2,
	GPIO_WHITE_LIGHT1,
	GPIO_WHITE_LIGHT2,
	GPIO_RESET_BTN,
	GPIO_SPK_PWR,
	GPIO_WIFI_PWR,
	GPIO_IRFEED,
	GPIO_WIFI_LED1,
	GPIO_WIFI_LED2,
	GPIO_VBUS_POWER,
    GPIO_BAT_CHARGE,
	GPIO_POW_DET,
	GPIO_POW_CTRL,
	GPIO_SD_ENABLE,
    GPIO_LTE4G_LED1,
    GPIO_LTE4G_LED2,
    GPIO_ALARM_LED1,
    GPIO_ALARM_LED2,
    GPIO_WPS_BTN,
    GPIO_POW_BTN,
    GPIO_CALL_BTN,              ///< 呼叫按键
    GPIO_HANGUP_BIN,            ///< 停止呼叫按键(挂断键)
    GPIO_POSITIVE_ALARM_BTN,    ///< 主动报警按键
    GPIO_LCD_BACKLIGHT,         ///< 屏幕背光
    GPIO_PCBA_CHECK,            ///< pcba 模式检测接口
    GPIO_PCBA_IND_LIGHT,        ///< pcba 状态指示灯
	GPIO_NUM_MAX = 32,
};

enum _mvp_backup_flag
{
    MVP_ENV_NORMAL = 0,
    MVP_ENV_BACKUP = 1,
    MVP_ENV_EMPTY = 2,      // 没有这个环境变量
};

extern mv_s32_t _gas32_gpio_def[GPIO_NUM_MAX];

#define gpio_ircut_ain1    _gas32_gpio_def[GPIO_IRCUT_A1]
#define gpio_ircut_bin1    _gas32_gpio_def[GPIO_IRCUT_B1]
#define gpio_ircut_ain2    _gas32_gpio_def[GPIO_IRCUT_A2]
#define gpio_ircut_bin2    _gas32_gpio_def[GPIO_IRCUT_B2]
#define gpio_reset_btn     _gas32_gpio_def[GPIO_RESET_BTN]
#define gpio_spk_power     _gas32_gpio_def[GPIO_SPK_PWR]
#define gpio_wifi_power    _gas32_gpio_def[GPIO_WIFI_PWR]
#define gpio_ir_led1       _gas32_gpio_def[GPIO_IR_LED1]
#define gpio_white_light1  _gas32_gpio_def[GPIO_WHITE_LIGHT1]
#define gpio_ir_led2       _gas32_gpio_def[GPIO_IR_LED2]
#define gpio_white_light2  _gas32_gpio_def[GPIO_WHITE_LIGHT2]
#define gpio_irfeed        _gas32_gpio_def[GPIO_IRFEED]
#define gpio_wifi_led1     _gas32_gpio_def[GPIO_WIFI_LED1]
#define gpio_wifi_led2     _gas32_gpio_def[GPIO_WIFI_LED2]
#define gpio_lte4g_led1    _gas32_gpio_def[GPIO_LTE4G_LED1]
#define gpio_lte4g_led2    _gas32_gpio_def[GPIO_LTE4G_LED2]
#define gpio_bat_charge    _gas32_gpio_def[GPIO_BAT_CHARGE]
#define gpio_pow_det       _gas32_gpio_def[GPIO_POW_DET]
#define gpio_pow_ctrl      _gas32_gpio_def[GPIO_POW_CTRL]
#define gpio_sd_enable     _gas32_gpio_def[GPIO_SD_ENABLE]
#define gpio_vbus_power    _gas32_gpio_def[GPIO_VBUS_POWER]
#define gpio_alarm_led1    _gas32_gpio_def[GPIO_ALARM_LED1]
#define gpio_alarm_led2    _gas32_gpio_def[GPIO_ALARM_LED2]
#define gpio_wps_btn       _gas32_gpio_def[GPIO_WPS_BTN]
#define gpio_pow_btn       _gas32_gpio_def[GPIO_POW_BTN]
#define gpio_call_btn      _gas32_gpio_def[GPIO_CALL_BTN]
#define gpio_hangup_btn    _gas32_gpio_def[GPIO_HANGUP_BIN]
#define gpio_posalarm_btn  _gas32_gpio_def[GPIO_POSITIVE_ALARM_BTN]
#define gpio_lcd_pwr       _gas32_gpio_def[GPIO_LCD_BACKLIGHT]

/* PCBA GPIO CFG */
#define gpio_pcba_check_gpio       _gas32_gpio_def[GPIO_PCBA_CHECK]
#define gpio_pcba_ind_light_gpio   _gas32_gpio_def[GPIO_PCBA_IND_LIGHT]

#ifndef CONFIG_PATH
#define CONFIG_PATH             "/mnt/mtd/"
#endif
#ifndef SDCARD_PATH
#define SDCARD_PATH             "/mnt/sdcard/"
#endif
#ifndef DB_DIR
#define DB_DIR         			CONFIG_PATH"mvconf/"			/* 新平台DB配置文件存放路径 */
#endif
/* 第一层配置结构(固件打包的配置) */
#define FIRMWARE_CFG_PATH       CONFIG_PATH"mvconf/default/firmware_cfg.ini"
/* 第二层配置结构(默认没有时用第一层配置进行覆盖，作为厂测更新配置使用) */
#define FACTORY_CFG_PATH        CONFIG_PATH"mvconf/default/factory_cfg.ini"
/* 第二点五层配置结构(用于已过厂测但需要在线更新配置时使用) */
#define ONLINE_CFG_PATH         CONFIG_PATH"mvconf/default/online_cfg.ini"      /* 用于在线更新配置 */

/* 第三层配置结构(设备运行生成的常驻配置+用户操作生成的配置) */
/** DEFAULT CONFIGS / USR CONFIGS (可直接复位删除的配置) */
#define AUTHORITY_INI	        CONFIG_PATH"mvconf/authority.ini"      ///< 设备能力配置文件
#define DEV_GPIO_INI            CONFIG_PATH"mvconf/dev_gpio_cfg.ini"   ///< gpio定义以及相关配置文件
#define DEV_PCBA_INI            CONFIG_PATH"mvconf/dev_pcba_cfg.ini"   ///< PCBA相关配置文件
#define DEV_TIME_INI            CONFIG_PATH"mvconf/dev_time_cfg.ini"   ///< 设备时间相关配置文件(默认配置：ntp校时)
#define DEV_BASEINFO_INI        CONFIG_PATH"mvconf/dev_baseinfo.ini"   ///< 设备基础信息配置文件
#define AVFRAME_ATTR_INI        CONFIG_PATH"mvconf/avframe_attr.ini"   ///< 音视频格式配置文件
#define RECORD_INI              CONFIG_PATH"mvconf/record.ini"         ///< 录像信息配置文件(默认配置)
#define USERINFO_INI            CONFIG_PATH"mvconf/usr_info.ini"       ///< 用户信息配置文件
#define VERSION_INI             CONFIG_PATH"mvconf/version.ini"        ///< 版本信息配置文件
#define ISP_SETTING_INI         CONFIG_PATH"mvconf/isp_settings.ini"   ///< ISP信息配置文件
#define NETWORK_INFO_INI        CONFIG_PATH"mvconf/network_info.ini"   ///< 网络模块配置文件
#define CUSTOM_OSD_INI	        CONFIG_PATH"mvconf/custom_osd.ini"     ///< 自定义osd配置文件
#define PTZ_PARAM_INI           CONFIG_PATH"mvconf/ptz_param.ini"      ///< 云台参数配置文件(默认配置)
#define MT_PARAM_INI            CONFIG_PATH"mvconf/mt_param.ini"       ///< 移动跟踪配置文件(默认配置)
#define ZOOM_PARAM_INI          CONFIG_PATH"mvconf/zoom_param.ini"     ///< 变焦配置文件
#define SPEECH_INI              CONFIG_PATH"mvconf/speech.ini"         ///< 语音参数配置文件
#define EXALARM_CONF_INI        CONFIG_PATH"mvconf/exalarm.ini"        ///< 报警参数配置文件
#define PATCHMANAGE_CONF        CONFIG_PATH"mvconf/patchmanage.conf"   ///< 版本管理配置文件
#define SCREEN_INFO_INI         CONFIG_PATH"mvconf/screen_info.ini"    ///< 屏幕相关配置文件
#define TWV_INFO_INI            CONFIG_PATH"mvconf/twv_info.ini"       ///< 双向视频通话配置文件
#define LIGHT_INFO_INI          CONFIG_PATH"mvconf/light_info.ini"     ///< 灯控配置文件
#define MISC_INFO_INI           CONFIG_PATH"mvconf/misc_info.ini"      ///< 杂项配置文件
#define VARIABLE_ARGS_INI       CONFIG_PATH"mvconf/variable_args.ini"  ///< 综合用户参数（复位删除; 包含录像、图像控制、麦克风+喇叭声音）
#define LTE4G_APNINFO_INI       CONFIG_PATH"mvconf/lte4g_apn_cfg.ini"  ///< 4G APN配置文件 只用于存储apn设置参数
#define UPGRADE_INFO_INI        CONFIG_PATH"mvconf/upgrade_info.ini"   ///< 升级信息配置文件(保存升级需要记录的信息)
#define LPM_INFO_INI            CONFIG_PATH"mvconf/lpm_info.ini"       ///< 低功耗配置文件

/** OTHER CONFIGS */
#define LOGCTRL_INFO_INI        CONFIG_PATH"mvconf/logctrl_info.ini"
#define RESET_MVS_CORE          CONFIG_PATH"mvconf/mvs_core.db"
#define LOGCTRL_INFO_INI_SDCARD SDCARD_PATH"logctrl_info.ini"
#define TIMING_INIO_SDCARD      SDCARD_PATH"sd_timing_info.ini"
#define DOWNGRADE_CONFIG_INI    SDCARD_PATH"fdgc.ini"

#ifndef SFDIR
#define SFDIR	      	  CONFIG_PATH"mvsound"
#endif
#pragma endregion config

#pragma region log

/***************************************************** ************************************/
extern mv_vptr_t mvpc_log_handle_get();
#define MVPC_LOG_ERR(fmt...) mvt_log_printf(mvpc_log_handle_get(), LOG_LEVEL_ERROR, fmt)
#define MVPC_LOG_WAR(fmt...) mvt_log_printf(mvpc_log_handle_get(), LOG_LEVEL_WARN,  fmt)
#define MVPC_LOG_INF(fmt...) mvt_log_printf(mvpc_log_handle_get(), LOG_LEVEL_INFO,  fmt)
#define MVPC_LOG_DBG(fmt...) mvt_log_printf(mvpc_log_handle_get(), LOG_LEVEL_DEBUG, fmt)
/******************************  MVS层公共log模块 end ************************************/
#pragma endregion log

mv_void_t mvp_plat_version();

#pragma region plat
/**
 * @brief  平台相关资源初始化
 * @return 初始化结果 
 * - success : MVVCD_EC_SUCCESS
 * -  failed : MVVCD_EC_FAILED
 */
mv_s32_t mvp_plat_source_init(mv_void_t);

/**
 * @brief  平台相关资源反初始化
 * @return 反初始化结果 
 * - success : MVVCD_EC_SUCCESS
 * -  failed : MVVCD_EC_FAILED
 */
mv_s32_t mvp_plat_source_uninit(mv_void_t);
#pragma endregion plat

#pragma region sys
mv_s32_t mvp_sys_reboot();
/**
 * @note  持续存在的进程使用该接口(例如udhcpc) 调用快速结束的可使用system(例如reboot)
 */
mv_s32_t mvp_system_call(mv_v8ptr_t cmd, mv_s32_t timeout);

mv_s32_t mvp_popen_call(mv_v8ptr_t cmd, mv_v8ptr_t out_data, mv_s32_t outsize_max, mv_s32_t timeout);

mv_u32_t mvp_get_mono_time();

mv_u64_t mvp_get_mono_time_ms();
#pragma region sys

#pragma region env
mv_s32_t mvp_env_init();

mv_s32_t mvp_env_get(mv_v8ptr_t section, mv_v8ptr_t key, mv_v8ptr_t value);

mv_s32_t mvp_env_set(mv_v8ptr_t section, mv_v8ptr_t key, mv_v8ptr_t value);

mv_s32_t mvp_env_update();

mv_s32_t mvp_env_uninit();
#pragma endregion env

mv_s32_t mvp_productID_check(mv_s32_t firmware_type, mv_s32_t product_id);

#pragma region server plat

typedef enum _server_plat
{
    SERVER_PLAT_V380   = 0,
    PLATFORM_TYPE_V380 = SERVER_PLAT_V380,
    SERVER_PLAT_XVV    = 3,
    PLATFORM_TYPE_XVV  = SERVER_PLAT_XVV,
}MVP_SERVER_PLAT_E;

mv_void_t mvp_platform_id_set(MVP_SERVER_PLAT_E plat_id);

mv_s32_t  mvp_platform_id_get(mv_void_t);

#pragma endregion server plat

#if __cplusplus
}
#endif

#endif

#if 0/*长电需要改接口实现如下*/
mv_void_t mvp_log_print(mv_s32_t type, mv_v8ptr_t module, mv_v8ptr_t fmt, ...)
{
#define BUFFERSIZE 4096

    mv_s32_t index = type - 1;
    index = (index < 0)?0:index;
    index = (index > 4)?0:index;

    struct {
        mv_u8_t    u8_color; /* 颜色代号 */
        mv_v8ptr_t pv8_tag;   /* 标签 */
    } _stru_map[] = {
        [MVP_LOG_DEF- 1] = {34, "DEF"}, /* 蓝色 */
        [MVP_LOG_ERR- 1] = {31, "ERR"}, /* 红色 */
        [MVP_LOG_WARN-1] = {33, "WARN"}, /* 黄色 */
        [MVP_LOG_INFO-1] = {32, "INFO"}, /* 绿色 */
        [MVP_LOG_DBG- 1] = {37, "DBG"}, /* 白色 */
    };

    time_t ts = 0;
    struct timespec tp = {0};
    clock_gettime(CLOCK_MONOTONIC, &tp);

    mv_s32_t h   = tp.tv_sec/3600;
    mv_s32_t m   = tp.tv_sec%86400%3600/60;
    mv_s32_t s   = tp.tv_sec%86400%3600%60;

    get_local_time_with_tz_cal_in(NULL, &ts);
    struct tm *p = localtime(&ts);

    mv_v8_t _av8_ts[64]           = {0};
    mv_v8_t _av8buf[BUFFERSIZE+1] = {0};

    mv_s32_t len = 0;
    mv_s32_t ret = 0;
    
    snprintf(_av8_ts, sizeof(_av8_ts),"[%04d-%02d-%02d %02d:%02d:%02d] [%d:%02d:%02d:%03lld] ", p->tm_year+1900, p->tm_mon+1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec,
            h, m, s, tp.tv_nsec/(1000*1000LL));

    if(module) {
        ret = snprintf(_av8buf, BUFFERSIZE-1, "[%s] [%s] ", _stru_map[index].pv8_tag, module);
    }
    else {
        ret = snprintf(_av8buf, BUFFERSIZE-1, "[%s] ", _stru_map[index].pv8_tag);
    }
    
    len += ret;

    va_list args;
    va_start(args, fmt);
    ret = vsnprintf(_av8buf+len, BUFFERSIZE-len-1, fmt, args);
    va_end(args);
    len += ret;
    len = (len>(BUFFERSIZE))?(BUFFERSIZE):len;

    if(_av8buf[len-1] == '\n') {// 去除\n
        len -= 1;
        _av8buf[len] = '\0';
    }

    printf("\033[1;%dm""%s""\033[1;%dm""%s""\033[0m\n", _stru_map[index].u8_color, _av8_ts, (index == 0)?0:_stru_map[index].u8_color, _av8buf);

#if defined(MV_DEBUG)
    pthread_mutex_lock(&log_mutex);
    write_tmp_file(_av8_ts, _av8buf, len);
    pthread_mutex_unlock(&log_mutex);
#endif
}
#endif